package com.ns.dcjh.ui.popup;

import android.content.Context;
import android.content.pm.ResolveInfo;
import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lxj.xpopup.core.BottomPopupView;
import com.ns.dcjh.R;
import com.ns.dcjh.ui.adapter.BrowserItemAdapter;

import java.util.List;

public class ChooseBrowserPopup extends BottomPopupView {

    private RecyclerView rv;

    private BrowserItemAdapter adapter;

    private List<ResolveInfo> list;

    private OnBrowserClickListener onBrowserClickListener;

    public ChooseBrowserPopup(@NonNull Context context, List<ResolveInfo> list) {
        super(context);
        this.list = list;
    }



    @Override
    protected int getImplLayoutId() {
        return R.layout.layout_browser_choose;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        rv = findViewById(R.id.browserPopupRv);
        GridLayoutManager manager = new GridLayoutManager(getContext(),4);
        rv.setLayoutManager(manager);
        adapter = new BrowserItemAdapter(R.layout.item_browser);
        rv.setAdapter(adapter);
        adapter.setNewData(list);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                onBrowserClickListener.onItemClick(list.get(position));
            }
        });

    }

    public void setOnBrowserClickListener(OnBrowserClickListener onBrowserClickListener) {
        this.onBrowserClickListener = onBrowserClickListener;
    }
}
